/**
 * Created by lesonli on 2016/11/17.
 */
import * as types from '../types'
import api from '../../api/modules/config'
import { getSaleUserList } from '../../api/modules/user'

const state = {
    saler_list: [],
    isLoading: false
}

// getters
// actions
const actions = {
    get_saler_list({ commit }) {
        if (!state.isLoading && state.saler_list.length === 0) {
            commit(types.SALER_LIST_LOADING);
            getSaleUserList().then((res) => {
                if (res.data.res_code === 1) {
                    commit(types.SALER_LIST_LOADED, res.data.msg);
                }
                else {
                    commit(types.SALER_LIST_LOADED, []);
                }
            });
        }
    },
}
// mutations
const mutations = {
    [types.SALER_LIST_LOADING](state) {
        state.isLoading = true;
    },
    [types.SALER_LIST_LOADED](state, list) {
        state.saler_list = list || state.saler_list;
        state.isLoading = false;
    }
}

export default {
    state,
    actions,
    mutations
}
